import { request } from "@/utils/request";
import { MenuResponseData, RoleData, RoleDataList } from "./type";
//枚举地址
enum API{
    //获取全部的职位
    ALLROLE_URL = '/admin/acl/role/',
    ADDROLE_URL = '/admin/acl/role/save',
    UPDATA_URL = '/admin/acl/role/update',
    //获取全部菜单数据
    ALLPERMISSTION = '/admin/acl/permission/toAssign/',
    //给相应职位分配权限
    SETPERMISTION_URL = '/admin/acl/permission/doAssign/?',
    //删除角色
    DELETEROLE_URl = '/admin/acl/role/remove/',
   
}
export const reqAllRoleList = (page:number,limit:number,roleName?:string)=>request.get<any,RoleDataList>(API.ALLROLE_URL+`${page}/${limit}/?roleName=${roleName}`)
//增加职位
export const reqUpdataAndAddRole = (data:RoleData)=>{
    if(data.id){
        return request.put<any,any>(API.UPDATA_URL)
    }else{
      return  request.post<any,any>(API.ADDROLE_URL,data)
    }
}
export const reqAllMenuList = (roleId:number)=>request.get<any,MenuResponseData>(API.ALLPERMISSTION+roleId)
//给相应职位下发权限
export const reqSetPermisstion = (roleId:number,permissionId:number[])=>request.post<any,any>(API.SETPERMISTION_URL+`roleId=${roleId}&&permissionId=${permissionId}`)

//删除角色
export const reqDeleteRole = (id:number)=>request.delete<any,any>(API.DELETEROLE_URl+id)
